package com.comleader.operator.service.strategy;

import java.util.HashMap;
import java.util.Map;

import com.comleader.operator.common.enums.OperatorInspectTypeEnum;
import com.comleader.operator.common.response.ResultEnum;
import com.comleader.operator.core.exception.BusinessException;

import cn.hutool.extra.spring.SpringUtil;

/**
 * @Dscription 检查策略工厂类
 * @Author 连新景
 * @Date 2024/02/26 17:52
 */
public class InspectStrategyFactory {

    private static InspectStrategyFactory factory = new InspectStrategyFactory();

    private static Map<Integer, Class> map = new HashMap<>(3);

    static {
        map.put(OperatorInspectTypeEnum.PERSONAL_USER.getType(), PersonalUserInspect.class);
        map.put(OperatorInspectTypeEnum.IOV_CARD.getType(), IovCardInspect.class);
        map.put(OperatorInspectTypeEnum.SMS_PORT.getType(), SmsPortInspect.class);
    }

    private InspectStrategyFactory() {

    }

    public static InspectStrategyFactory getInstance() {
        return factory;
    }

    public InspectStartegy get(Integer type) {
        Class clazz = map.get(type);
        if (clazz == null) {
            throw new BusinessException(ResultEnum.INVALID_BUSINESS_TYPE);
        }
        return (InspectStartegy)SpringUtil.getBean(clazz);
    }
}
